<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>动态师资</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="/assets/layui-v2.5.5/css/layui.css" media="all" />
</head>
<body>
<br/>
<form class="layui-form" action="">
<div class="layui-form-item">
    <div class="layui-inline">
    <label class="layui-form-label">地市：</label>
    	<div class="layui-input-block">
    		<select id="city" lay-filter="city">
			</select>
    	</div>
    </div>  
    <div class="layui-inline">
    <label class="layui-form-label">区县：</label>
    	<div class="layui-input-block">
    		<select id="county" lay-filter="county">
			</select>
    	</div>
    </div>
    <div class="layui-inline">
    <label class="layui-form-label">乡镇：</label>
    	<div class="layui-input-block">
    		<select id="town" lay-filter="town">
			</select>
    	</div>
    </div>  
    <div class="layui-inline">
    <label class="layui-form-label">行政村：</label>
    	<div class="layui-input-block">
    		<select id="village" lay-filter="village">
			</select>
    	</div>
    </div>  
</div> 
<div class="layui-form-item"> 
    <div class="layui-inline">
    <label class="layui-form-label">姓名：</label>
    <div class="layui-input-block">
    	<input type="text" name="name"  placeholder="请输入姓名" autocomplete="off" class="layui-input"/>
    </div>
    </div>
     <div class="layui-inline">
    <label class="layui-form-label">学校：</label>
    <div class="layui-input-block">
    	<input type="text" name="school"  placeholder="请输入学校" autocomplete="off" class="layui-input"/>
    </div>
    </div>
     <div class="layui-inline">
    <label class="layui-form-label">专业：</label>
    <div class="layui-input-block">
    	<input type="text" name="major"  placeholder="请输入专业" autocomplete="off" class="layui-input"/>
    </div>
    </div>
    <div class="layui-inline">
    <label class="layui-form-label">审核状态：</label>
    	<div class="layui-input-block">
   			<select name="isCheck" lay-verify="required">
				<option value="">全部</option>
			    <option value="未审">未审</option> 
			    <option value="通过">通过</option> 
			    <option value="未通过">未通过</option>  
			</select>
    	</div>
    </div> 
     <div class="layui-inline">
     &nbsp;&nbsp;<button type="button" class="layui-btn" onclick="searchTable();" >查询</button>
     &nbsp;&nbsp;<button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</div>
</form>
<table class="layui-hide" id="test" lay-filter="test" ></table>
<script type="text/html" id="toolbarDemo">
#for(x : powers)
	#if(x.pointcode == 'add')
		<button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon">&#xe654;</i>添加</button>
	#end
#end
</script>
<script type="text/html" id="barDemo">
#for(x : powers)
	#if(x.pointcode == 'detail')
		<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
	#else if(x.pointcode == 'edit')
		<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
	#else if(x.pointcode == 'del')
		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	#else if(x.pointcode == 'check')
		<a class="layui-btn layui-btn-xs" lay-event="check">审核</a>
	#else if(x.pointcode == 'upload')
		<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="upload">上传头像</a>
	#else if(x.pointcode == 'comment')
		<a class="layui-btn layui-btn-xs" lay-event="comment">评价管理</a>
	#end
#end
</script>
                        
<script src="/assets/layui-v2.5.5/layui.js" charset="utf-8"></script> 
<script src="/assets/js/area.js" charset="utf-8"></script> 
<script>
var $,table,form,mydata;
layui.use(['table','jquery','form'], function(){
	table = layui.table;
	form = layui.form;
	$ = layui.$;
	var areas=#(areas);
	if(areas.length==1){
		getAllCitys();
	}else if(areas.length==2){
		$('#city').append("<option value='"+areas[1].id+"' >"+areas[1].areaName+"</option>");
		$('#city').attr("disabled","disabled");
		searchCounty();
	}else if(areas.length==3){
		$('#city').append("<option value='"+areas[1].id+"' >"+areas[1].areaName+"</option>");
		$('#county').append("<option value='"+areas[2].id+"' >"+areas[2].areaName+"</option>");
		$('#city').attr("disabled","disabled");
		$('#county').attr("disabled","disabled");
		searchTown();
	}else if(areas.length==4){
		$('#city').append("<option value='"+areas[1].id+"' >"+areas[1].areaName+"</option>");
		$('#county').append("<option value='"+areas[2].id+"' >"+areas[2].areaName+"</option>");
		$('#town').append("<option value='"+areas[3].id+"' >"+areas[3].areaName+"</option>");
		$('#city').attr("disabled","disabled");
		$('#county').attr("disabled","disabled");
		$('#town').attr("disabled","disabled");
		searchVillage();	
	}else if(areas.length==5){
		$('#city').append("<option value='"+areas[1].id+"' >"+areas[1].areaName+"</option>");
		$('#county').append("<option value='"+areas[2].id+"' >"+areas[2].areaName+"</option>");
		$('#town').append("<option value='"+areas[3].id+"' >"+areas[3].areaName+"</option>");
		$('#village').append("<option value='"+areas[4].id+"' >"+areas[4].areaName+"</option>");
		$('#city').attr("disabled","disabled");
		$('#county').attr("disabled","disabled");
		$('#town').attr("disabled","disabled");
		$('#village').attr("disabled","disabled");
	}
	form.render('select');
	form.on('select(city)', function(data){
		searchCounty();
		form.render('select');
	});
	 form.on('select(county)', function(data){
			searchTown();
			form.render('select');
		});
	 form.on('select(town)', function(data){
			searchVillage();
			form.render('select');
		});
	//查询table
	    searchTable();
	  //监听头工具栏事件
	  table.on('toolbar(test)', function(obj){
	  var checkStatus = table.checkStatus(obj.config.id);
	  switch(obj.event){
	    case 'add':
	    	layer.open({
                type: 2,
                title: '添加师资',
                content:['/teacher/teacherAdd'] ,//允许出现滚动条
                area:['70%', '90%']
            });   
	    break;
	  };
	});
	  //监听行工具事件
	  table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
	    var data = obj.data //获得当前行数据
	    ,layEvent = obj.event; //获得 lay-event 对应的值
	    if(layEvent === 'detail'){
	    	  layer.open({
	                type: 2,
	                title: ['详情', 'height:40px;'],
	                content:data.contentUrl,
	                area:['70%', '90%'],
	      	  });   
		}else if(layEvent === 'del'){
   				layer.confirm('确定要进行此删除操作吗?', function(index){
   			        layer.close(index);	        
   			        $.ajax({
   			    	    url : '/teacher/teacherDel',
   			    		type : "post",
   			    		data : {id:data.id},
   			    		dataType : "json",
   			    		success : function(ret) {
   			    			if (ret.state == 'ok') {
   			    				layer.msg(ret.msg, {icon: 1, offset: '15px', time: 600}, function(){
   			    					var index = parent.layer.getFrameIndex(window.name);
   			    					parent.layer.close(index);
   			    					$(".layui-laypage-btn").click();
   			    				});
   			    			} else {
   			    				layer.msg(ret.msg, {icon: 2, offset: '10px'});
   			    			}
   			    		},
   			    		error: function() {
   			          } 
   			      });
   			   });				      
	    }else if(layEvent === 'setSign'){//海报预览
        	if(data.headImg==null){
				layer.msg("未上传头像！");
            }else{//预览图片
            	var imgHtml = "<img src='" + data.headImg + "' width='450px' height='450px'/>"; 
		    	layer.open({
		    		 type: 1,
		             area: [450 + 'px',500+'px'],
		             title: ['头像预览', 'height:40px;'], //设置标题width  
		             content: imgHtml, 
	            });
            }
        }else if(layEvent === 'edit'){
	       mydata = {
				data:JSON.stringify(data)
			};
   				layer.open({
   	                type: 2,
   	                title: '编辑师资',
   	                content:['/teacher/teacherEdit?areaCode='+data.areaCode] ,
   	                area:['70%', '90%']
   	            });			
	    }else if(layEvent === 'check'){
				layer.open({
                type: 2,
                title: '审核',
                content:['/teacher/teacherCheck?id='+data.id] ,
                area:['400px', '250px']
        	}); 		 	    			
	   }else if(layEvent === 'upload'){
			layer.open({
               type: 2,
               title: '上传头像',
               content:['/teacher/teacherUpload?id='+data.id] ,
               area:['600px', '200px']
           });    	
		}else if(layEvent === 'comment'){
			layer.open({
	               type: 2,
	               title: '评价管理',
	               content:['/teacher/teacherComment?id='+data.id] ,
	               area:['70%', '90%']
	           });    	
			}
	  });
});
function searchTable(){
	table.render({
	    elem: '#test'
	    ,url:'/teacher/paginate'
	    ,where: {city: $('#city').val().trim(),county: $('#county').val().trim(),town: $('#town').val().trim(), village: $('#village').val().trim(),
	    	name: $('input[name="name"]').val().trim(),school: $('input[name="school"]').val().trim(),major: $('input[name="major"]').val().trim(),
	    	isCheck: $('select[name="isCheck"]').val()} 
		,toolbar: '#toolbarDemo'
	    ,title: '师资表'
	    ,cols: [[
	      {field:'id', title:'ID', width:100, fixed: 'left', unresize: true}
	      ,{field:'name', title:'姓名', width:100}
	      ,{field:'school', title:'学校', width:100}
	      ,{field:'major', title:'专业', width:150}
	      ,{field:'tags', title:'风格', width:200}
	      ,{field:'areaName', title:'区划', width:100}
	      ,{field:'headImg', title:'头像', templet: function(d){if(d.headImg == null){return '未上传'}else{return '已上传'}}, width:100,event: 'setSign', style:'cursor: pointer;'}
	      ,{field:'createUserName', title:'发布人', width:100}
	      ,{field:'createAt', title:'创建时间', width:200,sort: true}
	      ,{field:'isCheck', title:'审核状态',width:100}
	      ,{fixed: '', title:'操作', toolbar: '#barDemo', width:400}
	    ]]
	    ,page: true
	    ,request: {     
	        pageName: 'pageNumber' //页码的参数名称，默认：page
	        ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
	    }
	  });
}
</script>
</body>
</html>